<template>
  <el-dialog
    title="扣款"
    :visible.sync="deductionVisible"
    :close-on-click-modal='false'
    center
    width="40%"
    :before-close="handleClose">
    <el-form label-position="left" ref="deductionFormRef" :rules="rules" label-width="100px" :model="deductionForm">
      <el-form-item label="扣款理由" prop="name">
        <el-input v-model="deductionForm.name"></el-input>
      </el-form-item>
      <el-form-item label="扣款金额" prop="deduction_price">
        <el-input v-model="deductionForm.deduction_price"></el-input>
      </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="sumbitDeduction('deductionFormRef')" v-no-more-click:3000>确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data () {
    return {
      deductionVisible: false,
      deductionForm: {
        name: '',
        deduction_price: ''
      },
      rules: {
        name: [{ required: true, message: '请输入扣款理由', trigger: 'blur' },],
        deduction_price: [{ required: true, message: '请输入扣款金额', trigger: 'blur' },]
      }
    }
  },
  methods: {
    show (data, pReview) {
      this.deductionVisible = true
      this.deductionForm.order_id = data.id
      this.deductionForm.opinion = pReview
      this.deductionForm.status = 2

    },
    sumbitDeduction (formName) {
      this.$refs[formName].validate((valid) => {
        if(valid) {
          this.$axios.post(`api/order/${this.deductionForm.order_id}/file_format_audit`, this.deductionForm)
          .then(res => {
            if(res.data.code == 200) {
              this.$alert('扣款成功！', '温馨提示！', {
                confirmButtonText: '确定',
                center: true,
                callback: action => {
                  this.handleClose()
                  this.$emit('refresh')
                }
              })
            } else {
              console.log(res.data.message)
            }
          })
          // .catch(errors => {
          //   this.$message.error(errors)
          // })
        } else {
          return false
        }
      })

    },
    handleClose () {
      this.$refs['deductionFormRef'].resetFields()
      this.deductionVisible = false
    }
  }

}
</script>

<style>

</style>
